﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Gw2WvWMapControl
{
    public class PercentageConverter : IMultiValueConverter
    {
        private static CultureInfo usCulture = new CultureInfo("en-US");

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType.Name == "Size")
            {
                Double[] param = parameter as Double[];
                System.Windows.Size size = new System.Windows.Size(param[0] * System.Convert.ToDouble(values[0], usCulture), param[1] * System.Convert.ToDouble(values[1], usCulture));
                Debug.WriteLine("Size:" + size);
                return size;
            }
            else if (targetType.Name == "Point")
            {
                Double[] param = parameter as Double[];
                System.Windows.Point point = new System.Windows.Point(param[0] * System.Convert.ToDouble(values[0], usCulture), param[1] * System.Convert.ToDouble(values[1], usCulture));
                Debug.WriteLine("Point:" + point);
                return point;
            }
            else if (targetType.Name == "Thickness")
            {
                double param = System.Convert.ToDouble(parameter, usCulture) * System.Convert.ToDouble(values[0], usCulture);
                Debug.WriteLine("Thickness:" + param);
                return new System.Windows.Thickness(param, param, 0, 0);
            }
            else
            {
                double param = System.Convert.ToDouble(parameter, usCulture);
                double output = System.Convert.ToDouble(values[0], usCulture) * param;
                Debug.WriteLine("Double:" + output);
                return output;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
